package com.jb.repair.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.jb.repair.common.AppConfig;
import com.jb.repair.model.BZGLSModeL;
import com.jb.repair.model.BZZLModel;
import com.jb.repair.model.DepartmentModel;
import com.jb.repair.model.DzjlModel;
import com.jb.repair.model.EqDefectTypeModel;
import com.jb.repair.model.EqDeptFormModel;
import com.jb.repair.model.EqFormCustomFieldsModle;
import com.jb.repair.model.EqFormCustomFieldsValueModel;
import com.jb.repair.model.EqFormStdFildsModel;
import com.jb.repair.model.EqLayerFormModel;
import com.jb.repair.model.EqModelModel;
import com.jb.repair.model.EqNavModel;
import com.jb.repair.model.EqProducerModel;
import com.jb.repair.model.EqTypeModel;
import com.jb.repair.model.FileLbModel;
import com.jb.repair.model.FssbModel;
import com.jb.repair.model.ItemModel;
import com.jb.repair.model.JxjlModel;
import com.jb.repair.model.LedgerModel;
import com.jb.repair.model.PlaceModel;
import com.jb.repair.model.PositionModel;
import com.jb.repair.model.QxjlModel;
import com.jb.repair.model.ResultModel;
import com.jb.repair.model.ResultStatisticModel;
import com.jb.repair.model.SbbjModel;
import com.jb.repair.model.Sbzl2Model;
import com.jb.repair.model.SbzlModel;
import com.jb.repair.model.SiSettingModel;
import com.jb.repair.model.SysCodeModel;
import com.jb.repair.model.TaskModel;
import com.jb.repair.model.TtjlModel;
import com.jb.repair.model.UpdateLedger4Json;
import com.jb.repair.model.UserModel;
import com.jb.repair.model.YcjlModel;
import com.jb.repair.model.YdjlModel;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by gaobin on 2015/12/1.
 */
public class InsertDb {

    private String TAG = "db";
    private static SQLiteDatabase db;
    private static InsertDb mydb;
    // 每1000条提交一次事务
    private static int MAX = 1000;

    private InsertDb(Context context) {
        db = context.getApplicationContext().openOrCreateDatabase(AppConfig.DB_PATh, Context.MODE_PRIVATE, null);
    }

    public static synchronized InsertDb getInstance(Context context) {
        if (mydb == null)
            mydb = new InsertDb(context);
        return mydb;
    }

    private void closeDb() {
        db.close();
        mydb = null;
    }

    /**
     * 添加或更新统计情况
     * @param list
     */
    public void insertOrUpdateStatistic(List<ResultStatisticModel> list) {
        if (list == null) return;

        for (ResultStatisticModel model : list) {
            String q = "select 0 from TB_SI_TASK_RESULT_STATISTICAL where task_id = '" + model.task_id + "'";
            Cursor c = db.rawQuery(q, null);

            ContentValues cv = new ContentValues();
            cv.put("upload_time", model.upload_time);
            cv.put("si_person", model.si_person);
            cv.put("si_time", model.si_time);
            cv.put("task_id", model.task_id);
            cv.put("QX_COUNT", model.QX_COUNT);
            cv.put("YC_COUNT", model.YC_COUNT);
            cv.put("total_si_num", model.total_si_num);
            cv.put("total_forgot_num", model.total_forgot_num);
            cv.put("total_must_si_com_num", model.total_must_si_com_num);
            cv.put("total_must_si_forgot_num", model.total_must_si_forgot_num);


            if (c.moveToNext()) {  //表中存在该条记录执行改操作
//                db.update("TB_SI_TASK_RESULT_STATISTICAL", cv, "task_id=?", new String[]{model.task_id});
            } else { //表中没有该条记录执行插入操作
//                db.insert("TB_SI_TASK_RESULT_STATISTICAL", null, cv);
                // 暂时不操作了，因为下载下来的DB里没有YC_COUNT字段
            }
            c.close();
        }
    }

    /**
     * 获取最近七天下发的任务
     * @param {String} - userId 用户id
     * @return {List<String>} 当前用户最近7天的所有任务（A/B角均包括）
     */
    public List<String> getRecentTask(String userId) {
        // 只显示最近1天的任务（今天）
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date curDate = new Date(System.currentTimeMillis());//获取当前时间
        Date severalDaysAgo = new Date(curDate.getTime() - 0 * 24 * 60 * 60 * 1000);
        String several = "'" + formatter.format(severalDaysAgo) + " 00:00:00'";
        String sql = "SELECT distinct(GUID) from TB_SI_TASK " +
                "where (si_person_a_id='" + userId + "' or si_person_b_id='" + userId + "') " +
                "and del_mark!='T' and task_date >= " + several + " order by task_date desc";

        List<String> ids = new ArrayList<String>();
        Cursor c = db.rawQuery(sql, null);
        while (c.moveToNext()) {
            ids.add(c.getString(0));
        }

        c.close();

        return ids;
    }

    /**
     *
     */
    public void insertTask(List<TaskModel> taskModelList) {
        // 每MAX条提交一次事务
        int count = MAX;
        db.beginTransaction();
        if (taskModelList != null && taskModelList.size() > 0)
            for (int i = 0, len = taskModelList.size(); i < len; i++) {

                if (count == 0) {
                    // 结束上一次事务
                    db.setTransactionSuccessful();
                    db.endTransaction();

                    // 开启新的事务
                    db.beginTransaction();
                    count = MAX;
                    Log.i("completed: ", "has inserted " + i + " tasks");
                }
                count--; // 计数

                TaskModel model = taskModelList.get(i);
                Cursor c = db.rawQuery("select 0 from tb_si_task where GUID='" + model.guid + "'", null);
              //  Log.i("abc", "select * from tb_si_task where GUID='" + model.guid + "'");
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.guid);
                cv.put("task", model.task);
                cv.put("plan_id", model.plan_id);
                cv.put("plan", model.plan);
                cv.put("eq_dept_id", model.eq_dept_id);
                cv.put("eq_dept", model.eq_dept);
                cv.put("si_person_a_id", model.si_person_a_id);
                cv.put("si_person_a", model.si_person_a);
                cv.put("si_person_b_id", model.si_person_b_id);
                cv.put("si_person_b", model.si_person_b);
                cv.put("task_date", model.task_date);
                cv.put("task_status", model.task_status);
                cv.put("del_mark", model.del_mark);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    Log.i(TAG, "表中存在该条记录");
                    db.update("tb_si_task", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("tb_si_task", null, cv);
                }
                c.close();
            }

        Log.i("completed: ", "has inserted " + taskModelList.size() + " tasks");

        // 提交最后一次事务
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    /**
     *
     */
    public void insertTaskResult(List<ResultModel> resultModelList) {
        db.beginTransaction();
        Cursor c;

        // 每MAX条提交一次事务
        int count = MAX;

        if (resultModelList != null && resultModelList.size() > 0) {
            Log.i("gaobin", "结果list长度：" + resultModelList.size());
            for (int i = 0, len = resultModelList.size(); i < len; ++i) {

                if (count == 0) {
                    // 结束上一次事务
                    db.setTransactionSuccessful();
                    db.endTransaction();

                    // 开启新的事务
                    db.beginTransaction();
                    count = MAX;
                    Log.i("completed: ", "has inserted " + i + " taskResults");
                }
                count--; // 计数

                // Log.i("sss", i + "");
                ResultModel model = resultModelList.get(i);
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.guid);
                cv.put("task_id", model.task_id);
                cv.put("task", model.task);
                cv.put("plan_task_detail_id", model.plan_task_detail_id);
                cv.put("is_must_today", model.is_must_today);
                cv.put("desc_result", model.desc_result);
                cv.put("num_result", model.num_result);
                cv.put("is_abnormal", model.is_abnormal);
                cv.put("is_defect", model.is_defect);
                cv.put("abnormal_desc", model.abnormal_desc);
                cv.put("defect_desc", model.defect_desc);
                cv.put("defect_level_id", model.defect_level_id);
                cv.put("defect_type_guid", model.defect_type_id);
                cv.put("si_person_id", model.si_person_id);
                cv.put("si_person", model.si_person);
                cv.put("si_time", model.si_time);
                cv.put("is_forgot", model.is_forgot);
                cv.put("power_plant_id9", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);

                cv.put("plan_id", model.plan_id);
                cv.put("plan", model.plan);
                cv.put("dev_id", model.dev_id);
                cv.put("dev_name", model.dev_name);
                cv.put("place_id", model.place_id);
                cv.put("place", model.place);
                cv.put("si_standard", model.si_standard);
                cv.put("position", model.position);
                cv.put("content", model.content);
                cv.put("standard", model.standard);
                cv.put("cycle", model.cycle);
                cv.put("method", model.method);
                cv.put("tools", model.tools);
                cv.put("standard_max", model.standard_max);
                cv.put("standard_min", model.standard_min);
                cv.put("standard_normal", model.standard_normal);
                cv.put("unit", model.unit);
                cv.put("del_mark", model.del_mark);

                c = db.rawQuery("select 0 from tb_si_task_result where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("tb_si_task_result", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("tb_si_task_result", null, cv);
                }
                c.close();
            }
        }

        Log.i("completed: ", "has inserted " + resultModelList.size() + " taskResults");
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertPos(List<PositionModel> positionModelList) {
        db.beginTransaction();
        if (positionModelList != null && positionModelList.size() > 0) {
            for (int i = 0; i < positionModelList.size(); i++) {
                PositionModel model = positionModelList.get(i);
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.guid);
                cv.put("eq_dept_id", model.eq_dept_id);
                cv.put("dev_name", model.ins_position_name);
                cv.put("place_id", model.note);
                cv.put("place", model.tranfer_fieid);
                cv.put("position", model.power_plant_id);
                cv.put("content", model.creat_time);
                cv.put("standard", model.update_time);
                Cursor c = db.rawQuery("select 0 from tb_dev_ins_position where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("tb_dev_ins_position", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("tb_dev_ins_position", null, cv);
                }
                c.close();
            }
        }
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    /**
     *
     */
    public void insertItem(List<ItemModel> itemModelList) {
        db.beginTransaction();
        Log.i("gaobin", "项目list长度：" + itemModelList.size());
        if (itemModelList != null && itemModelList.size() > 0)
            for (int i = 0; i < itemModelList.size(); i++) {
                ItemModel model = itemModelList.get(i);
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.guid);
                cv.put("dev_id", model.dev_id);
                cv.put("dev_name", model.dev_name);
                cv.put("place_id", model.place_id);
                cv.put("place", model.place);
                cv.put("position", model.position);
                cv.put("content", model.content);
                cv.put("standard", model.standard);
                cv.put("cycle", model.cycle);
                cv.put("method", model.method);
                cv.put("tools", model.tools);
                cv.put("standard_max", model.standard_max);
                cv.put("standard_min", model.standard_min);
                cv.put("unit", model.unit);
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("is_must_today", model.isMust ? "T" : "F");
                Cursor c = db.rawQuery("select 0 from tb_si_task_result where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("tb_si_task_result", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("tb_si_task_result", null, cv);
                }
                c.close();
            }
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertFile(List<FileLbModel> fileModelList) {
        db.beginTransaction();
        if (fileModelList != null && fileModelList.size() > 0)
            for (int i = 0; i < fileModelList.size(); i++) {
                FileLbModel model = fileModelList.get(i);
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.guid);
                cv.put("OBJ_ID", model.obj_id);
                cv.put("LX", model.lx);
                cv.put("WJMC", model.wjmc);
                Cursor c = db.rawQuery("select 0 from tb_file_lb where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("tb_file_lb", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("tb_file_lb", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }


    public void insertPerson(List<UserModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                UserModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.guid);
                cv.put("CORP_ID", model.CORP_ID);
                cv.put("PERS_JOBID", model.PERS_JOBID);
                cv.put("PERS_ID", model.PERS_ID);
                cv.put("PERS_NAME", model.PERS_NAME);
                cv.put("LOGO_ID", model.LOGIN_ID);
                cv.put("LOGO_PASS", model.LOGO_PASS);
                cv.put("MOBILE_PHONE", model.MOBILE_PHONE);
                cv.put("DEPT_ID", model.DEPT_ID);
                cv.put("DN", model.DN);
                cv.put("SFDL", model.SFDL);
                cv.put("DLRQ", model.DLRQ);
                cv.put("OBJ_CAPTION", model.OBJ_CAPTION);
                cv.put("CLS_ID", model.CLS_ID);
                cv.put("FLOWSTATUS", model.FLOWSTATUS);
                //  cv.put("OBJ_DISPLDX", model.OBJ_DISPLDX);
                cv.put("SEX", model.SEX);
                cv.put("AGE", model.AGE);
                Cursor c = db.rawQuery("select 0 from TB_SYS_PERSON where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_SYS_PERSON", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_SYS_PERSON", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertDepart(List<DepartmentModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                DepartmentModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.guid);
                cv.put("CORP_ID", model.CORP_ID);
                cv.put("DEPT_ID", model.DEPT_ID);
                cv.put("DEPT_NAME", model.DEPT_NAME);
                cv.put("DEPT_TYPE", model.DEPT_TYPE);
                cv.put("SUPER_DEPT", model.SUPER_DEPT);
                cv.put("DN", model.DN);
                cv.put("SFZF", model.SFZF);
                cv.put("ZFRQ", model.ZFRQ);
                cv.put("BZ", model.BZ);
                cv.put("DWJB", model.DWJB);
                cv.put("FLOWSTATUS", model.FLOWSTATUS);
                cv.put("BMQC", model.BMQC);
                cv.put("CLS_ID", model.CLS_ID);
                cv.put("TIMEPOINT", model.TIMEPOINT);
                Cursor c = db.rawQuery("select 0 from TB_SYS_DEPARTMENT where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_SYS_DEPARTMENT", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_SYS_DEPARTMENT", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertPlace(List<PlaceModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                PlaceModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("GUID", model.guid);
                cv.put("eq_dept_id", model.eq_dept_id);
                cv.put("unit_id", model.unit_id);
                cv.put("place_id", model.place_id);
                cv.put("place_type_id", model.place_type_id);
                cv.put("si_env_enable", model.si_env_enable);
                cv.put("si_type", model.si_type);
                cv.put("qrcode_id", model.qrcode_id);
                cv.put("nfc_id", model.nfc_id);
                cv.put("rfid_id", model.rfid_id);
                Cursor c = db.rawQuery("select 0 from TB_SI_PLACE where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_SI_PLACE", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_SI_PLACE", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertBZZL(List<BZZLModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                BZZLModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("FJID", model.fjid);
             //   cv.put("power_plant_id", model.UPLOADOR);
                cv.put("CREATE_TIME", model.creat_time);
                cv.put("UPDATE_TIME", model.update_time);
                cv.put("GUID", model.guid);
               // cv.put("eq_dept_id", model.TYPE);
                Cursor c = db.rawQuery("select 0 from TB_BZ_BZGL where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_BZ_BZGL", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_BZ_BZGL", null, cv);
                }
                c.close();
            }
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertBZZLS(List<BZGLSModeL> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                BZGLSModeL model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("TYPE", model.TYPE);
                cv.put("PID", model.PID);
                cv.put("UPDATE_TIME", model.UPDATE_TIME);
                cv.put("GUID", model.guid);
                Cursor c = db.rawQuery("select 0 from TB_BZ_BZGLS where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_BZ_BZGLS", cv, "GUID=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_BZ_BZGLS", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqtype(List<EqTypeModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqTypeModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("guid", model.guid);
                cv.put("eq_imp_type", model.eq_imp_type);
                cv.put("eq_type_code", model.eq_type_code);
                cv.put("eq_type_name", model.eq_type_name);
                cv.put("eq_dept_id", model.eq_dept_id);
                cv.put("creat_user_id", model.creat_user_id);
                Cursor c = db.rawQuery("select 0 from TB_EQ_TYPE where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_TYPE", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_TYPE", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqModel(List<EqModelModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqModelModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("guid", model.guid);
                cv.put("eq_dept_id", model.eq_dept_id);
                cv.put("eq_imp_model", model.eq_imp_model);
                cv.put("eq_model_code", model.eq_model_code);
                cv.put("eq_model_name", model.eq_model_name);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                Cursor c = db.rawQuery("select 0 from TB_EQ_MODEL where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_MODEL", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_MODEL", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqPro(List<EqProducerModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqProducerModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.eq_imp_producer);
                cv.put("guid", model.guid);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("producer_name", model.producer_name);
                cv.put("short_producer_name", model.short_producer_name);
                cv.put("creat_user_id", model.creat_user_id);
                Cursor c = db.rawQuery("select 0 from TB_EQ_PRODUCER where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_PRODUCER", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_PRODUCER", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqNav(List<EqNavModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqNavModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_name", model.layer_name);
                cv.put("layer_code", model.layer_code);
                cv.put("layer_type", model.layer_type);
                cv.put("parent_id", model.parent_id);
                cv.put("link_dept_id", model.link_dept_id);
                cv.put("config_show_content", model.config_show_content);
                cv.put("sort", model.sort);
                Cursor c = db.rawQuery("select 0 from TB_EQ_NAV where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_NAV", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_NAV", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertLedger(List<LedgerModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                LedgerModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_edetp_id", model.eq_edetp_id);
                cv.put("eq_name", model.eq_name);
                cv.put("eq_type_id", model.eq_type_id);
                cv.put("eq_model_id", model.eq_model_id);
                cv.put("eq_producer_id", model.eq_producer_id);
                cv.put("eq_postion_id", model.eq_postion_id);
                cv.put("eq_imp_type", model.eq_imp_type);
                cv.put("eq_imp_model", model.eq_imp_model);
                //   cv.put("eq_imp_producer", model.eq_imp_producer);
                cv.put("eq_imp_postion", model.eq_imp_postion);
                cv.put("eq_operation_date", model.eq_operation_date);
                cv.put("eq_level", model.eq_level);
                cv.put("eq_code", model.eq_code);
                cv.put("eq_tech_parameter", model.eq_tech_parameter);
                Cursor c = db.rawQuery("select 0 from TB_EQ_BASICINFO where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_BASICINFO", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_BASICINFO", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqLayerForm(List<EqLayerFormModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqLayerFormModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("form_code", model.form_code);
                cv.put("order_num", model.order_num);
                Cursor c = db.rawQuery("select 0 from TB_EQ_LAYER_FORM where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_LAYER_FORM", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_LAYER_FORM", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertFssb(List<FssbModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                FssbModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("attacheq_name", model.attacheq_name);
                cv.put("code_editable", model.code_editable);
                cv.put("model", model.model);
                cv.put("tech_parameter_editable", model.tech_parameter_editable);
                cv.put("producer_editable", model.producer_editable);
                cv.put("num_editable", model.num_editable);
                cv.put("operation_date_editable", model.operation_date_editable);
                cv.put("attachment", model.attachment);
                cv.put("attachment_path", model.attachment_path);
                Cursor c = db.rawQuery("select 0 from TB_EQ_ATTACHEQ where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_ATTACHEQ", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_ATTACHEQ", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertSbzl(List<SbzlModel> list) {
        Log.i(TAG,"本次插入的数据数为："+list.size());
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                SbzlModel model = list.get(i);
                Log.i(TAG,model.toString());
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("file_type_id", model.file_type_id);
                cv.put("file_name", model.file_name);
                cv.put("file_format_editable", model.file_format_editable);
                cv.put("file_version_editable", model.file_version_editable);
                cv.put("file_status", model.file_status);
                cv.put("FJID", model.fjid);
                cv.put("attachment_path", model.attachment_path);
                cv.put("zl_status",model.zl_status);
                cv.put("eq_edetp_names",model.eq_edetp_names);
                cv.put("layer_names",model.layer_names);
                cv.put("eq_names",model.eq_names);
                cv.put("file_code",model.file_code);
                Log.i(TAG,"guid = "+model.guid);
                Cursor c = db.rawQuery("select * from TB_EQ_FILES where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    Log.i(TAG,"执行更新操作");
                    db.update("TB_EQ_FILES", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    Log.i(TAG,"执行插入操作");
                    db.insert("TB_EQ_FILES", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }
    public void insertSbzl2(List<Sbzl2Model> list) {
        Log.i(TAG,"本次插入的数据数为："+list.size());
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                Sbzl2Model model = list.get(i);
                Log.i(TAG,model.toString());
                ContentValues cv = new ContentValues();
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("file_code",model.file_code);
                cv.put("eq_edetp_id",model.eq_edetp_id);
                Log.i(TAG,"guid = "+model.guid);
                Cursor c = db.rawQuery("select * from TB_FILE_EQ_REF where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    Log.i(TAG,"执行更新操作");
                    db.update("TB_FILE_EQ_REF", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    Log.i(TAG,"执行插入操作");
                    db.insert("TB_FILE_EQ_REF", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }





    public void insertSbbj(List<SbbjModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                SbbjModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("spar_name", model.spar_name);
                cv.put("spar_code_editable", model.spar_code_editable);
                cv.put("model", model.model);
                cv.put("tech_parameter_editable", model.tech_parameter_editable);
                cv.put("producer", model.producer);
                cv.put("unit", model.unit);
                cv.put("quota_num_editable", model.quota_num_editable);
                cv.put("price_editable", model.price_editable);
                cv.put("stock_num", model.stock_num);
                cv.put("storage_location_editable", model.storage_location_editable);
                cv.put("category_id", model.category_id);
                Cursor c = db.rawQuery("select 0 from TB_EQ_SPAREPARTS where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_SPAREPARTS", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_SPAREPARTS", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertYcjl(List<YcjlModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                YcjlModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("eq_id", model.eq_id);
                cv.put("layer_code", model.layer_code);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("source_id", model.source_id);
                cv.put("found_time", model.found_time);
                cv.put("foundman_id", model.foundman_id);
                cv.put("abn_describe", model.abn_describe);
                cv.put("abn_status", model.abn_status);
                cv.put("solvedman_id_editable", model.solvedman_id_editable);
                cv.put("solved_time_editable", model.solved_time_editable);
                cv.put("dealtype_id", model.dealtype_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("attachment", model.attachment);
                cv.put("attachment_path", model.attachment_path);
                cv.put("inspect_id", model.inspect_id);
                cv.put("patrol_id", model.patrol_id);
                Cursor c = db.rawQuery("select 0 from TB_EQ_ABNORMAL where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_ABNORMAL", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_ABNORMAL", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertQxjl(List<QxjlModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                QxjlModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("source_id", model.source_id);
                cv.put("found_time", model.found_time);
                cv.put("foundman_id", model.foundman_id);
                cv.put("level_id", model.level_id);
                cv.put("type_id", model.type_id);
                cv.put("defect_describe", model.defect_describe);
                cv.put("defect_status", model.defect_status);
                cv.put("solved_result", model.solved_result);
                cv.put("attachment", model.attachment);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("attachment_path", model.attachment_path);
                cv.put("inspect_id", model.inspect_id);
                cv.put("patrol_id", model.patrol_id);
                Cursor c = db.rawQuery("select 0 from TB_EQ_DEFECT where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_DEFECT", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_DEFECT", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertYdjl(List<YdjlModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                YdjlModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("yidong_describe", model.yidong_describe);
                cv.put("yidong_reason", model.yidong_reason);
                cv.put("yidong_time", model.yidong_time);
                cv.put("supervisor_id", model.supervisor_id);
                cv.put("attachment", model.attachment);
                cv.put("attachment_path", model.attachment_path);
                Cursor c = db.rawQuery("select 0 from TB_EQ_YIDONG where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_YIDONG", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_YIDONG", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertJxjl(List<JxjlModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                JxjlModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("level_id", model.level_id);
                cv.put("maintenance_time", model.maintenance_time);
                cv.put("maintenance_describe", model.maintenance_describe);
                cv.put("supervisor_id", model.supervisor_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("attachment", model.attachment);
                cv.put("attachment_path", model.attachment_path);
                Cursor c = db.rawQuery("select 0 from TB_EQ_MAINTENANCE where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_MAINTENANCE", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_MAINTENANCE", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertDzjl(List<DzjlModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                DzjlModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("action_describe", model.action_describe);
                cv.put("action_time", model.action_time);
                cv.put("appraise", model.appraise);
                cv.put("incorrect_reason", model.incorrect_reason);
                cv.put("dept_name_editable", model.dept_name_editable);
                cv.put("is_lubo_ok_editable", model.is_lubo_ok_editable);
                cv.put("attachment", model.attachment);
                cv.put("attachment_path", model.attachment_path);
                Cursor c = db.rawQuery("select 0 from TB_EQ_RELAYACTION where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_RELAYACTION", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_RELAYACTION", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertTtjl(List<TtjlModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                TtjlModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("guid", model.guid);
                cv.put("layer_code", model.layer_code);
                cv.put("eq_id", model.eq_id);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("exit_time", model.exit_time);
                cv.put("startup_time", model.startup_time);
                cv.put("exit_function", model.exit_function);
                cv.put("exit_describe", model.exit_describe);
                cv.put("is_fault_exit_editable", model.is_fault_exit_editable);
                cv.put("attachment", model.attachment);
                cv.put("attachment_path", model.attachment_path);
                cv.put("attacheq_id", model.attacheq_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("update_user_id", model.update_user_id);
                Cursor c = db.rawQuery("select 0 from TB_EQ_TUOTUI where GUID='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_TUOTUI", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_TUOTUI", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqFormCusField(List<EqFormCustomFieldsModle> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqFormCustomFieldsModle model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("form_code", model.form_code);
                cv.put("cus_name", model.cus_name);
                cv.put("field_format", model.field_format);
                cv.put("possible_values", model.possible_values);
                cv.put("min_length", model.min_length);
                cv.put("max_length", model.max_length);
                cv.put("is_filter", model.is_filter);
                cv.put("is_required", model.is_required);
                cv.put("is_show_eqbook", model.is_show_eqbook);
                cv.put("eq_detp_id", model.eq_detp_id);
                cv.put("searchable", model.searchable);
                cv.put("default_value", model.default_value);
                cv.put("editable", model.editable);
                cv.put("is_show_eqbook", model.is_show_eqbook);
                cv.put("description", model.description);
                cv.put("order_num", model.order_num);
                Cursor c = db.rawQuery("select 0 from TB_EQ_FORM_CUSTOMFIELDS where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_FORM_CUSTOMFIELDS", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_FORM_CUSTOMFIELDS", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqCusFieldValue(List<EqFormCustomFieldsValueModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqFormCustomFieldsValueModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("customdfield_id", model.customdfield_id);
                cv.put("value", model.value);
                cv.put("belongrow_guid", model.belongrow_guid);
                Cursor c = db.rawQuery("select 0 from TB_EQ_FORM_CUSTOMFIELDS_VALUE where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_FORM_CUSTOMFIELDS_VALUE", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_FORM_CUSTOMFIELDS_VALUE", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqStdField(List<EqFormStdFildsModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqFormStdFildsModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("field_code", model.field_code);
                cv.put("form_code", model.form_code);
                cv.put("field_name", model.field_name);
                cv.put("visible", model.visible);
                cv.put("is_required", model.is_required);
                cv.put("order_num", model.order_num);
                Cursor c = db.rawQuery("select 0 from TB_EQ_FORM_STDFIELDS where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_FORM_STDFIELDS", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_FORM_STDFIELDS", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertDefectType(List<EqDefectTypeModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqDefectTypeModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("note", model.eq_type_code);
                cv.put("power_plant_id", model.defect_type);
                Cursor c = db.rawQuery("select 0 from TB_EQ_DEFECT_TYPE where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_DEFECT_TYPE", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_DEFECT_TYPE", null, cv);
                }
                c.close();
            }
        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertEqDeptForm(List<EqDeptFormModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                EqDeptFormModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("note", model.eq_dept_id);
                cv.put("power_plant_id", model.from_code);
                cv.put("creat_time", model.order_num);
                Cursor c = db.rawQuery("select 0 from TB_EQ_DEPT_FORM where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_EQ_DEPT_FORM", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_EQ_DEPT_FORM", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertSetting(List<SiSettingModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                SiSettingModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("note", model.note);
                cv.put("power_plant_id", model.power_plant_id);
                cv.put("creat_time", model.creat_time);
                cv.put("update_time", model.update_time);
                cv.put("update_user_id", model.update_user_id);
                cv.put("creat_user_id", model.creat_user_id);
                cv.put("guid", model.guid);
                cv.put("person_guid", model.person_guid);
                cv.put("volume_set_app", model.volume_set_app);
                Cursor c = db.rawQuery("select 0 from TB_SI_SETTING where guid='" + model.guid + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_SI_SETTING", cv, "guid=?", new String[]{model.guid});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_SI_SETTING", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertCode(List<SysCodeModel> list) {
        db.beginTransaction();
        if (list != null && list.size() > 0)
            for (int i = 0; i < list.size(); i++) {
                SysCodeModel model = list.get(i);
                ContentValues cv = new ContentValues();
                cv.put("GUID", model.GUID);
                cv.put("CATEGORY_CODE", model.CATEGORY_CODE);
                cv.put("LABEL_CODE", model.LABEL_CODE);
                cv.put("CODE", model.CODE);
                cv.put("CODE_ALLAS", model.CODE_ALLAS);
                cv.put("CODE_NAME", model.CODE_NAME);
                cv.put("IF_USE", model.IF_USE);
                cv.put("TIMEPOINT", model.TIMEPOINT);
                cv.put("REMARK", model.REMARK);
                Cursor c = db.rawQuery("select 0 from TB_SYS_CODE where GUID='" + model.GUID + "'", null);
                if (c.moveToNext()) {  //表中存在该条记录执行改操作
                    db.update("TB_SYS_CODE", cv, "GUID=?", new String[]{model.GUID});
                } else { //表中没有该条记录执行插入操作
                    db.insert("TB_SYS_CODE", null, cv);
                }
                c.close();
            }

        db.setTransactionSuccessful();
        db.endTransaction();
    }

    public void insertLedger(UpdateLedger4Json uc4j) {
        db.beginTransaction();
        this.insertFile(uc4j.tb_file_lb);
        this.insertPerson(uc4j.tb_sys_person);
        this.insertDepart(uc4j.tb_sys_department);
        this.insertPlace(uc4j.tb_si_place);
        this.insertBZZL(uc4j.tb_bz_bzgl);
        this.insertBZZLS(uc4j.tb_bz_bzgls);
        this.insertEqtype(uc4j.tb_eq_type);
        this.insertEqModel(uc4j.tb_eq_model);
        this.insertEqPro(uc4j.tb_eq_producer);
        this.insertEqNav(uc4j.tb_eq_nav);
        this.insertEqLayerForm(uc4j.tb_eq_layer_form);
        this.insertLedger(uc4j.tb_eq_basicinfo);
        this.insertFssb(uc4j.tb_eq_attacheq);
        this.insertSbzl(uc4j.tb_eq_files);
        this.insertSbzl2(uc4j.tb_file_eq_ref);
        this.insertSbbj(uc4j.tb_eq_spareparts);
        this.insertYcjl(uc4j.tb_eq_abnormal);
        this.insertQxjl(uc4j.tb_eq_defect);
        this.insertJxjl(uc4j.tb_eq_maintenance);
        this.insertDzjl(uc4j.tb_eq_relayaction);
        this.insertTtjl(uc4j.tb_eq_tuotui);
        this.insertYdjl(uc4j.tb_eq_yidong);
        this.insertEqFormCusField(uc4j.tb_eq_form_customfields);
        this.insertEqStdField(uc4j.tb_eq_form_stdfields);
        this.insertEqCusFieldValue(uc4j.tb_eq_form_customfields_value);
        this.insertEqDeptForm(uc4j.tb_eq_dept_form);
        this.insertDefectType(uc4j.tb_eq_defect_type);
        this.insertSetting(uc4j.tb_si_setting);
        this.insertCode(uc4j.tb_sys_code);

        db.setTransactionSuccessful();
        db.endTransaction();
    }
}
